from realtors.models import Realtor
from django.shortcuts import render
from django.http import HttpResponse
from listings.choices import price_choices, bedroom_choices, state_choices

from listings.models import Listing
from realtors.models import Realtor

# Create your views here.

def index(request):
    #对引入的数据进行筛选
    listings = Listing.objects.order_by('list_date').filter(is_published=True)[:3]
    #将筛选后的数据传到网页的模板当中
    context = {
        'listings': listings,
        'state_choices': state_choices,
        'bedroom_choices': bedroom_choices,
        'price_choices': price_choices
    }

    return render(request, 'pages/index.html', context)

def about(request):
    #Get all Realtors
    realtors = Realtor.objects.order_by('-hire_date')
    #Get MVP
    mvp_realtor = Realtor.objects.all().filter(is_mvp=True)

    context = {
        'realtors': realtors,
        'mvp_realtor': mvp_realtor
        }
    return render(request, 'pages/about.html', context)
